package fileoutputobjects;

import java.util.Random;

/**
 * This simulator moves erratically across the field of view. Each move, it selects a location uniformly randomly in a 
 * square determined by the constants below.
 * 
 * @author Trevor Terris
 *
 */
public class DrunkenWalker extends HumanSimulator
{
    //Determines the maximum amount the simulation can move in each direction
    //TODO: Set these values.
    private double myMaxXStep = 0.02;
    private double myMaxZStep = 0.02;
    
    /**
     * The constructor. Takes the ID of the item. 
     * 
     * @param thisID
     */
    public DrunkenWalker(MutableInteger thisID, Random r)
    {
        setRandom(r);
        myID = thisID.intValue();
        thisID.increment();
        setNewPositions();
    }
    
    /**
     * Randomly chooses a position to move to whose X-value is within a certain distance of the current X coordinate, and 
     * whose Z value is within a certain distance of the current Z coordinate.
     */
    public void step()
    {
        //The original values are stored, in case the position has to be recalculated several times.
        double originalX = myXCoord;
        double originalZ = myZCoord;

        myXCoord += 2 * myMaxXStep * myRandom.nextDouble() - myMaxXStep;
        myZCoord += 2 * myMaxZStep * myRandom.nextDouble() - myMaxZStep;
        
        //If the initial value chosen is out of bounds, it keeps trying to find a value within the bounds.
        while (!isInBounds())
        {
            myXCoord = originalX + 2 * myMaxXStep * myRandom.nextDouble() - myMaxXStep;
            myZCoord = originalZ + 2 * myMaxZStep * myRandom.nextDouble() - myMaxZStep;
        }
    }
}
